function error_value = processing_error_2d(left, right, bottom, top, Nx, Ny, basis_type, N_gauss_int2d, function_u, U, error_type)

[node, elem] = processing_node_elem_bdary_2d(left, right, bottom, top, Nx, Ny, basis_type, "Dirichlet");
dN = reference_basis_function_2d(basis_type);

switch error_type
    case "L2"
        sum_n = 0;
        for n = 1:size(elem,1)
            E = node(elem(n,:),:);
            switch basis_type
                case {"P1", "P1b", "P2"}
                    V = E(1:3,1:2);
                    psi = function_transform_2d([0,0; 1,0; 0,1], dN, V);
                case {"Q1", "Q1b", "Q2"}
                    V = E(1:4,1:2);
                    psi = function_transform_2d([-1,-1; 1,-1; 1,1; -1,1], dN, V);
            end
            sum_u = @(x,y) 0;
            switch basis_type
                case {"P1", "P1b", "P2"}
                    for k = 1:size(elem,2)
                        i = elem(n,k);
                        sum_u = @(x,y) sum_u(x,y) + U(i).*psi{k}(x,y);
                    end
                    int_func = @(x,y) (function_u(x,y) - sum_u(x,y)).^2;
                    sum_n = sum_n + gauss_int2d_tri(int_func, V(1,:), V(2,:), V(3,:), N_gauss_int2d);
                case {"Q1", "Q1b", "Q2"}
                    for k = 1:size(elem,2)
                        i = elem(n,k);
                        sum_u = @(x,y) sum_u(x,y) + U(i).*psi{k}(x,y);
                    end
                    int_func = @(x,y) (function_u(x,y) - sum_u(x,y)).^2;
                    sum_n = sum_n + gauss_int2d_rec(int_func, V(1,:), V(2,:), V(3,:), V(4,:), N_gauss_int2d);
            end
        end
        error_value = sqrt(sum_n);

    case "H1"

    otherwise
        error('Invalid error type.')
end

end